<?php
/* 
 * ********* CVS HEADER ********* 
 * 
 * $RCSfile: usermod.php,v $ 
 * $Date: 2007/04/16 09:57:18 $ 
 * $Revision: 1.3 $ 
 * 
 * ********* CVS HEADER ********* 
 */
require_once("module/TPLN/TPLN.php");
$TPLN = new TPLN;

$TPLN -> Open($op_basepath."tpl/usermod.html");
$TPLN -> IncludeFile("header", "environnement/".$session["environnement"]."/header.php");
$TPLN -> IncludeFile("footer", "environnement/".$session["environnement"]."/footer.php");

$L_erreur   = false;
$L_message1 = "";
$L_message2 = "";
$L_message3 = "";
$L_msg_err ="<br/><font color=\"#FF0000\">";
$L_msg_err.="Mot de passe invalide";
$L_msg_err.="</font>";
if($confirm==1) {
	$query ="UPDATE utilisateur";
	require_once(get_path_module("password.password"));
	if (isset($user_submit)) {
		/* Update user information */
		$query.=" SET nom='$nom', prenom='$prenom', email='$email'";
		if (!checkUserPassword($session['id_user'],md5($user_passwd))) {
			$L_erreur=true;
			$L_message1 =$L_msg_err;
		}
	} else if (isset($passwd_submit)) {
		/* Update password */
		if (!checkUserPassword($session['id_user'],md5($old_passwd))) {
			$L_erreur=true;
			$L_message2 = $L_msg_err;
		} else {
			if ((""!=$passwd) ||
				(""!=$passwd_confirm)) {
						if (checkPassword($passwd,$passwd_confirm)) {
							$passwd=md5($passwd_confirm);
							$query.=" SET password='$passwd'";
						} else {
							/* Erreur */
							$L_erreur=true;
							$L_message3 = $L_msg_err;
						}
			} else {
				/* Erreur */
				$L_erreur=true;
				$L_message3 = $L_msg_err;
			}
		}			
	} else {
		/* None of variable set ?????? */
	}
	if (!$L_erreur) {
		$query.=" WHERE id='".$session['id_user']."'";  
		@rportalrequete($query) or rportalerreur($query, "?op=");
		
		$session["prenom"] = $prenom;
		$session["nom"] = $nom;
		$session["email"] = $email;
		$_SESSION["session"] = $session;
		header("Location: ?op=useraff");
		exit;
	}
}
$L_bloc="afficher";
$TPLN -> Parse($L_bloc.".message1", $L_message1);
$TPLN -> Parse($L_bloc.".message2", $L_message2);
$TPLN -> Parse($L_bloc.".message3", $L_message3);

$query="SELECT * FROM utilisateur WHERE id='".$session['id_user']."'";
$result=rportalrequete($query) or rportalerreur($query, "?op=");
if($row=rportalligne($result)) {
	$TPLN -> Parse($L_bloc.".user_login", $row["login"]);	
	$TPLN -> Parse($L_bloc.".user_nom", $row["nom"]);
	$TPLN -> Parse($L_bloc.".user_prenom", $row["prenom"]);
	$TPLN -> Parse($L_bloc.".user_email", $row["email"]);
} else {
	$TPLN -> EraseBloc($L_bloc);
}

require_once(get_path_module("admin")); 
$pc = new panneau_controle(); 
$pc->calculRubriqueParFonction($op); 
$TPLN->Parse("panneau_controle",$pc->retourneEntete());

$TPLN->Write();

?>